import {
  Controller,
  UseInterceptors,
  UploadedFile,
  Post,
  Get,
  Res
} from '@nestjs/common'
import { UploadService } from './upload.service'
import { FileInterceptor } from '@nestjs/platform-express/multer'
import { join } from 'path'
import { Response } from 'express'
import { Public } from 'src/auth/guards/public.guard'
import { NoAuth } from 'src/role/decorators/no-auth.decorator'
@Public()
@NoAuth()
@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @Post()
  @UseInterceptors(FileInterceptor('file'))
  uploadFile(@UploadedFile() file) {
    return file.filename
  }
  @Get('export')
  downLoad(@Res() res: Response) {
    const url = join(__dirname, '../images/1662894316133.png')
    res.download(url)
  }
  @Get('stream')
  async down(@Res() res: Response) {
    // const url = join(__dirname, '../images/1662894316133.png')
    // const tarStream = new zip.Stream()
    // await tarStream.addEntry(url)
    // res.setHeader('Content-Type', 'application/octet-stream')
    // res.setHeader('Content-Disposition', `attachment; filename=xiaoman`)
    // tarStream.pipe(res)
    return true
  }
}
